package com.letv.whatslive.mysql.mybatis.pay;

import com.letv.ugc.common.database.mybatis.page.Page;
import com.letv.whatslive.model.mysql.pay.LehiActivitySpecialUser;
import com.letv.whatslive.model.mysql.pay.LehiActivitySpecialUserExample;
import com.letv.whatslive.model.mysql.pay.LehiActivitySpecialUserKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by shenyue1 on 2016/8/2.
 */
@Component
public class LehiActivitySpecialUserDao {
    @Autowired
    private LehiActivitySpecialUserMapper lehiActivitySpecialUserMapper;

    public int insertSelective(LehiActivitySpecialUser record){
        return lehiActivitySpecialUserMapper.insertSelective(record);
    }

    public int insert(LehiActivitySpecialUser record){
        return lehiActivitySpecialUserMapper.insert(record);
    }

    public int updateByPrimaryKeySelective(LehiActivitySpecialUser record){
        return lehiActivitySpecialUserMapper.updateByPrimaryKeySelective(record);
    }

    public List<LehiActivitySpecialUser> selectAll(Map<String,Object> params,Integer pageSize,Integer pageNo){
        LehiActivitySpecialUserExample example = new LehiActivitySpecialUserExample();
        example.setOrderByClause("rank asc");
        LehiActivitySpecialUserExample.Criteria criteria=example.createCriteria();
        if(params!=null&&!params.isEmpty()){
            if(params.get("activityId")!=null)
                criteria.andActivityIdEqualTo((Integer) params.get("activityId"));
            if(params.get("rank")!=null)
                criteria.andRankEqualTo((Short) params.get("rank"));
            if(params.get("userId")!=null)
                criteria.andUserIdEqualTo((Long) params.get("userId"));
        }
        return lehiActivitySpecialUserMapper.selectByExample(example, new Page(pageNo, pageSize));
    }

    public int deleteByPrimaryKey(Integer activityId,Long userId){
        LehiActivitySpecialUserKey lehiActivitySpecialUserKey=new LehiActivitySpecialUser();
        lehiActivitySpecialUserKey.setActivityId(activityId);
        lehiActivitySpecialUserKey.setUserId(userId);
        return lehiActivitySpecialUserMapper.deleteByPrimaryKey(lehiActivitySpecialUserKey);
    }
}
